using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {
	
	/// <summary>
	/// Bank (target)
	/// </summary>
	public GameObject bank;
	public Vector3 bankPos;
	
	/// <summary>
	/// Attributes
	/// </summary>
	public float movSpeed;
	public int damage;
	public int hp;
    public int bounty;
	private bool acting;

	private GameManager gameManager;
	
	void Start ()
	{
		gameManager = GameObject.FindGameObjectWithTag("Manager").GetComponent<GameManager>();
		bank = GameObject.FindGameObjectWithTag("Bank");
		bankPos = new Vector3(bank.transform.position.x, transform.position.y, bank.transform.position.z);
		movSpeed = Random.Range (movSpeed - 1, movSpeed + 1);
		acting = false;
	}
	
	void Update () 
	{
		if (acting == false)
		{
			transform.Translate(Vector3.forward * movSpeed * Time.deltaTime);
			transform.LookAt(bankPos);
		}
		
		if(hp <= 0)
		{
            gameManager.addGold(bounty);
			gameManager._enemy++;
			Destroy(gameObject);

            GameObject.FindGameObjectWithTag("Player").layer = 10;
		}
	}
	
	public void setActing (bool act)
	{
		this.acting = act;	
	}
	
	public void loseHp(int damage)
	{
		hp -= damage;
	}
	
	void OnCollisionEnter (Collision other)
	{
		if (other.gameObject.tag == "Bank")
		{
			gameManager.bankHit(damage);
			Destroy(gameObject);
		}
	}
}